package com.esri.core.geometry;

import com.esri.core.geometry.Geometry;
import com.github.mikephil.charting.utils.Utils;

/* loaded from: classes.dex */
public final class MultiPathImpl extends MultiVertexGeometryImpl {
    static int[] a = {0, 0, 6, 0, 8, 0};
    private int e;
    protected boolean m_bPathStarted;
    protected boolean m_bPolygon;
    protected double m_cachedArea2D;
    protected double m_cachedLength2D;
    protected AttributeStreamOfDbl m_cachedRingAreas2D;
    protected int m_curveParamwritePoint;
    protected Point m_moveToPoint;
    protected AttributeStreamOfInt8 m_pathFlags;
    protected AttributeStreamOfInt32 m_paths;
    protected AttributeStreamOfInt8 m_segmentFlags;
    protected AttributeStreamOfInt32 m_segmentParamIndex;
    protected AttributeStreamOfDbl m_segmentParams;

    protected void _finishLineTo() {
    }

    @Override // com.esri.core.geometry.Geometry
    public Object _getImpl() {
        return this;
    }

    public boolean hasNonLinearSegments() {
        return this.m_curveParamwritePoint > 0;
    }

    public MultiPathImpl(boolean z) {
        this.m_bPolygon = z;
        this.m_bPathStarted = false;
        this.m_curveParamwritePoint = 0;
        this.m_cachedLength2D = Utils.DOUBLE_EPSILON;
        this.m_cachedArea2D = Utils.DOUBLE_EPSILON;
        this.m_pointCount = 0;
        this.m_description = VertexDescriptionDesignerImpl.d();
        this.m_cachedRingAreas2D = null;
        this.e = 0;
    }

    public MultiPathImpl(boolean z, VertexDescription vertexDescription) {
        if (vertexDescription == null) {
            throw new IllegalArgumentException();
        }
        this.m_bPolygon = z;
        this.m_bPathStarted = false;
        this.m_curveParamwritePoint = 0;
        this.m_cachedLength2D = Utils.DOUBLE_EPSILON;
        this.m_cachedArea2D = Utils.DOUBLE_EPSILON;
        this.m_pointCount = 0;
        this.m_description = vertexDescription;
        this.m_cachedRingAreas2D = null;
        this.e = 0;
    }

    protected void _initPathStartPoint() {
        i();
        Point point = this.m_moveToPoint;
        if (point == null) {
            this.m_moveToPoint = new Point(this.m_description);
        } else {
            point.a(this.m_description);
        }
    }

    public void startPath(double d, double d2) {
        Point2D point2D = new Point2D();
        point2D.x = d;
        point2D.y = d2;
        startPath(point2D);
    }

    public void startPath(Point2D point2D) {
        _initPathStartPoint();
        this.m_moveToPoint.a(point2D);
        this.m_bPathStarted = true;
    }

    public void startPath(Point3D point3D) {
        _initPathStartPoint();
        this.m_moveToPoint.a(point3D);
        a(this.m_moveToPoint.getDescription());
        this.m_bPathStarted = true;
    }

    public void startPath(Point point) {
        if (point.isEmpty()) {
            throw new IllegalArgumentException();
        }
        _initPathStartPoint();
        point.copyTo(this.m_moveToPoint);
        this.m_bPathStarted = true;
    }

    protected void _beforeNewSegment(int i) {
        if (this.m_bPathStarted) {
            _initPathStartPoint();
            AttributeStreamOfInt32 attributeStreamOfInt32 = this.m_paths;
            if (attributeStreamOfInt32 == null) {
                AttributeStreamOfInt32 attributeStreamOfInt322 = (AttributeStreamOfInt32) AttributeStreamBase.createIndexStream(2);
                this.m_paths = attributeStreamOfInt322;
                attributeStreamOfInt322.write(0, 0);
                this.m_pathFlags = (AttributeStreamOfInt8) AttributeStreamBase.createByteStream(2, (byte) 0);
            } else {
                attributeStreamOfInt32.resize(attributeStreamOfInt32.size() + 1, Utils.DOUBLE_EPSILON);
                AttributeStreamOfInt8 attributeStreamOfInt8 = this.m_pathFlags;
                attributeStreamOfInt8.resize(attributeStreamOfInt8.size() + 1, Utils.DOUBLE_EPSILON);
            }
            if (this.m_bPolygon) {
                AttributeStreamOfInt8 attributeStreamOfInt82 = this.m_pathFlags;
                attributeStreamOfInt82.write(attributeStreamOfInt82.size() - 2, (byte) 1);
            }
            i++;
        }
        int i2 = this.m_pointCount;
        AttributeStreamOfInt32 attributeStreamOfInt323 = this.m_paths;
        attributeStreamOfInt323.write(attributeStreamOfInt323.size() - 1, this.m_pointCount + i);
        d(i + i2);
        this.m_pathFlags.write(this.m_paths.size() - 1, (byte) 0);
        if (this.m_bPathStarted) {
            setPointByVal(i2, this.m_moveToPoint);
            this.m_bPathStarted = false;
        }
    }

    public void lineTo(double d, double d2) {
        _beforeNewSegment(1);
        setXY(this.m_pointCount - 1, d, d2);
        _finishLineTo();
    }

    public void lineTo(Point2D point2D) {
        _beforeNewSegment(1);
        setXY(this.m_pointCount - 1, point2D);
        _finishLineTo();
    }

    public void lineTo(Point3D point3D) {
        _beforeNewSegment(1);
        setXYZ(this.m_pointCount - 1, point3D);
        _finishLineTo();
    }

    public void lineTo(Point point) {
        _beforeNewSegment(1);
        setPointByVal(this.m_pointCount - 1, point);
        _finishLineTo();
    }

    protected void _initSegmentData(int i) {
        if (this.m_segmentParamIndex == null) {
            this.m_segmentFlags = (AttributeStreamOfInt8) AttributeStreamBase.createByteStream(this.m_pointCount, (byte) 1);
            this.m_segmentParamIndex = (AttributeStreamOfInt32) AttributeStreamBase.createIndexStream(this.m_pointCount, -1);
        }
        int i2 = this.m_curveParamwritePoint + i;
        AttributeStreamOfDbl attributeStreamOfDbl = this.m_segmentParams;
        if (attributeStreamOfDbl == null) {
            this.m_segmentParams = (AttributeStreamOfDbl) AttributeStreamBase.createAttributeStreamWithPersistence(1, i2);
        } else {
            attributeStreamOfDbl.resize(i2, Utils.DOUBLE_EPSILON);
        }
    }

    protected void _finishBezierTo() {
        this.m_segmentFlags.write(this.m_pointCount - 2, (byte) 2);
    }

    public void bezierTo(Point2D point2D, Point2D point2D2, Point2D point2D3) {
        _beforeNewSegment(1);
        setXY(this.m_pointCount - 1, point2D3);
        _initSegmentData(6);
        AttributeStreamOfInt8 attributeStreamOfInt8 = this.m_pathFlags;
        attributeStreamOfInt8.setBits(attributeStreamOfInt8.size() - 1, (byte) 2);
        this.m_segmentParamIndex.write(this.m_pointCount - 2, this.m_curveParamwritePoint);
        int i = this.m_curveParamwritePoint + 6;
        this.m_curveParamwritePoint = i;
        this.m_segmentParams.write(i, point2D.x);
        this.m_segmentParams.write(i + 1, point2D.y);
        this.m_segmentParams.write(i + 2, Utils.DOUBLE_EPSILON);
        this.m_segmentParams.write(i + 3, point2D2.x);
        this.m_segmentParams.write(i + 4, point2D2.y);
        this.m_segmentParams.write(i + 5, Utils.DOUBLE_EPSILON);
        _finishBezierTo();
    }

    public void openPath(int i) {
        i();
        if (this.m_bPolygon) {
            throw new GeometryException("internal error");
        }
        getPathCount();
        if (i > getPathCount()) {
            throw new IllegalArgumentException();
        }
        AttributeStreamOfInt8 attributeStreamOfInt8 = this.m_pathFlags;
        if (attributeStreamOfInt8 == null) {
            throw new GeometryException("internal error");
        }
        attributeStreamOfInt8.a(i, (byte) 1);
    }

    public void openPathAndDuplicateStartVertex(int i) {
        i();
        if (this.m_bPolygon) {
            throw new GeometryException("internal error");
        }
        int pathCount = getPathCount();
        if (i > pathCount) {
            throw new GeometryException("internal error");
        }
        if (isClosedPath(i)) {
            if (this.m_pathFlags == null) {
                throw new GeometryException("nternal_error");
            }
            int i2 = this.m_pointCount;
            int pathStart = getPathStart(i);
            int pathEnd = getPathEnd(i);
            d(this.m_pointCount + 1);
            _verifyAllStreams();
            int attributeCount = this.m_description.getAttributeCount();
            for (int i3 = 0; i3 < attributeCount; i3++) {
                if (this.b[i3] != null) {
                    int componentCount = VertexDescription.getComponentCount(this.m_description._getSemanticsImpl(i3));
                    this.b[i3].insertRange(componentCount * pathEnd, this.b[i3], componentCount * pathStart, componentCount, true, 1, componentCount * i2);
                }
            }
            while (pathCount > i) {
                this.m_paths.write(pathCount, this.m_paths.read(pathCount) + 1);
                pathCount--;
            }
            this.m_pathFlags.a(i, (byte) 1);
        }
    }

    public void openAllPathsAndDuplicateStartVertex() {
        i();
        if (this.m_bPolygon) {
            throw new GeometryException("internal error");
        }
        if (this.m_pathFlags == null) {
            throw new GeometryException("nternal_error");
        }
        _verifyAllStreams();
        int pathCount = getPathCount();
        int i = 0;
        for (int i2 = 0; i2 < pathCount; i2++) {
            if (this.m_pathFlags.read(i2) == 1) {
                i++;
            }
        }
        int attributeCount = this.m_description.getAttributeCount();
        for (int i3 = 0; i3 < attributeCount; i3++) {
            if (this.b[i3] != null) {
                int componentCount = VertexDescription.getComponentCount(this.m_description._getSemanticsImpl(i3));
                this.b[i3].resize((this.m_pointCount + i) * componentCount);
                int i4 = pathCount;
                int i5 = i;
                for (int i6 = this.m_pointCount - 1; i6 >= 0; i6--) {
                    if (i6 + 1 == this.m_paths.read(i4)) {
                        i4--;
                        if (this.m_pathFlags.read(i4) == 1) {
                            int read = this.m_paths.read(i4);
                            for (int i7 = 0; i7 < componentCount; i7++) {
                                this.b[i3].writeAsDbl(((i5 + i6) * componentCount) + i7, this.b[i3].readAsDbl((componentCount * read) + i7));
                            }
                            i5--;
                            if (i5 == 0) {
                                break;
                            }
                        }
                    }
                    for (int i8 = 0; i8 < componentCount; i8++) {
                        this.b[i3].writeAsDbl(((i5 + i6) * componentCount) + i8, this.b[i3].readAsDbl((componentCount * i6) + i8));
                    }
                }
            }
        }
        int i9 = i;
        while (pathCount > 0) {
            this.m_paths.write(pathCount, this.m_paths.read(pathCount) + i9);
            int i10 = pathCount - 1;
            if (this.m_pathFlags.read(i10) == 1) {
                this.m_pathFlags.a(i10, (byte) 1);
                i9--;
                if (i9 == 0) {
                    break;
                }
            }
            pathCount--;
        }
        this.m_pointCount += i;
    }

    public void closePathWithLine() {
        i();
        if (b()) {
            throw new GeometryException("Invalid call. This operation cannot be performed on an empty geometry.");
        }
        this.m_bPathStarted = false;
        int size = this.m_paths.size() - 2;
        this.m_pathFlags.write(size, (byte) (this.m_pathFlags.read(size) | 1));
        AttributeStreamOfInt8 attributeStreamOfInt8 = this.m_segmentFlags;
        if (attributeStreamOfInt8 != null) {
            attributeStreamOfInt8.write(this.m_pointCount - 1, (byte) 1);
            this.m_segmentParamIndex.write(this.m_pointCount - 1, -1);
        }
    }

    public void closeAllPaths() {
        i();
        if (this.m_bPolygon || b()) {
            return;
        }
        this.m_bPathStarted = false;
        int size = this.m_paths.size() - 1;
        for (int i = 0; i < size; i++) {
            if (!isClosedPath(i)) {
                this.m_pathFlags.write(i, (byte) (this.m_pathFlags.read(i) | 1));
            }
        }
    }

    public static int getSegmentDataSize(byte b) {
        return a[b];
    }

    public void closePathWithBezier(Point2D point2D, Point2D point2D2) {
        i();
        if (b()) {
            throw new GeometryException("Invalid call. This operation cannot be performed on an empty geometry.");
        }
        this.m_bPathStarted = false;
        int size = this.m_paths.size() - 2;
        this.m_pathFlags.write(size, (byte) (this.m_pathFlags.read(size) | 1 | 2));
        _initSegmentData(6);
        byte read = this.m_segmentFlags.read((byte) ((this.m_pointCount - 1) & 7));
        this.m_segmentFlags.write(this.m_pointCount - 1, (byte) 2);
        int i = this.m_curveParamwritePoint;
        if (getSegmentDataSize(read) < getSegmentDataSize((byte) 2)) {
            this.m_segmentParamIndex.write(this.m_pointCount - 1, this.m_curveParamwritePoint);
            this.m_curveParamwritePoint += 6;
        } else {
            i = this.m_segmentParamIndex.read(this.m_pointCount - 1);
        }
        this.m_segmentParams.write(i, point2D.x);
        this.m_segmentParams.write(i + 1, point2D.y);
        this.m_segmentParams.write(i + 2, Utils.DOUBLE_EPSILON);
        this.m_segmentParams.write(i + 3, point2D2.x);
        this.m_segmentParams.write(i + 4, point2D2.y);
        this.m_segmentParams.write(i + 5, Utils.DOUBLE_EPSILON);
    }

    public boolean isClosedPath(int i) {
        return ((byte) (this.m_pathFlags.read(i) & 1)) != 0;
    }

    public boolean hasNonLinearSegments(int i) {
        return (this.m_pathFlags.read(i) & 2) != 0;
    }

    public void addSegment(Segment segment, boolean z) {
        mergeVertexDescription(segment.getDescription());
        if (segment.getType() == Geometry.Type.LINE) {
            Point point = new Point();
            if (z || isEmpty()) {
                segment.queryStart(point);
                startPath(point);
            }
            segment.queryEnd(point);
            lineTo(point);
            return;
        }
        throw new GeometryException("internal error");
    }

    public void addEnvelope(Envelope2D envelope2D, boolean z) {
        boolean z2 = this.m_pointCount == 0;
        startPath(envelope2D.xmin, envelope2D.ymin);
        if (z) {
            lineTo(envelope2D.xmax, envelope2D.ymin);
            lineTo(envelope2D.xmax, envelope2D.ymax);
            lineTo(envelope2D.xmin, envelope2D.ymax);
        } else {
            lineTo(envelope2D.xmin, envelope2D.ymax);
            lineTo(envelope2D.xmax, envelope2D.ymax);
            lineTo(envelope2D.xmax, envelope2D.ymin);
        }
        closePathWithLine();
        this.m_bPathStarted = false;
        if (!z2 || z) {
            return;
        }
        _setDirtyFlag(64, false);
    }

    public void addEnvelope(Envelope envelope, boolean z) {
        if (envelope.isEmpty()) {
            return;
        }
        boolean z2 = this.m_pointCount == 0;
        Point point = new Point(this.m_description);
        for (int i = 0; i < 4; i++) {
            envelope.queryCornerByVal(z ? (4 - i) - 1 : i, point);
            if (i == 0) {
                startPath(point);
            } else {
                lineTo(point);
            }
        }
        closePathWithLine();
        this.m_bPathStarted = false;
        if (!z2 || z) {
            return;
        }
        _setDirtyFlag(64, false);
    }

    public void add(MultiPathImpl multiPathImpl, boolean z) {
        for (int i = 0; i < multiPathImpl.getPathCount(); i++) {
            addPath(multiPathImpl, i, !z);
        }
    }

    public void addPath(MultiPathImpl multiPathImpl, int i, boolean z) {
        AttributeStreamOfInt8 pathFlagsStreamRef;
        AttributeStreamOfInt8 attributeStreamOfInt8;
        if (i >= multiPathImpl.getPathCount()) {
            throw new IllegalArgumentException();
        }
        this.m_bPathStarted = false;
        mergeVertexDescription(multiPathImpl.m_description);
        int i2 = this.m_pointCount;
        int pathSize = multiPathImpl.getPathSize(i) + i2;
        d(pathSize);
        _verifyAllStreams();
        multiPathImpl._verifyAllStreams();
        int attributeCount = this.m_description.getAttributeCount();
        for (int i3 = 0; i3 < attributeCount; i3++) {
            int _getSemanticsImpl = this.m_description._getSemanticsImpl(i3);
            int attributeIndex = multiPathImpl.m_description.getAttributeIndex(_getSemanticsImpl);
            if (attributeIndex >= 0 && multiPathImpl.b[attributeIndex] != null) {
                int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
                int i4 = componentCount * i2;
                this.b[i3].insertRange(i4, multiPathImpl.b[attributeIndex], componentCount * multiPathImpl.getPathStart(i), componentCount * multiPathImpl.getPathSize(i), z, componentCount, i4);
            }
        }
        this.m_paths.add(pathSize);
        if (multiPathImpl.hasNonLinearSegments(i)) {
            AttributeStreamOfInt8 segmentFlagsStreamRef = multiPathImpl.getSegmentFlagsStreamRef();
            if (this.m_segmentFlags == null) {
                this.m_segmentFlags = (AttributeStreamOfInt8) AttributeStreamBase.createByteStream(i2, (byte) 1);
                this.m_segmentParamIndex = (AttributeStreamOfInt32) AttributeStreamBase.createIndexStream(i2, -1);
            }
            AttributeStreamOfInt32 segmentIndexStreamRef = getSegmentIndexStreamRef();
            AttributeStreamOfDbl segmentDataStreamRef = getSegmentDataStreamRef();
            int pathStart = multiPathImpl.getPathStart(i);
            int pathSize2 = multiPathImpl.getPathSize(i) + multiPathImpl.getPathStart(i);
            for (int i5 = pathStart; i5 < pathSize2; i5++) {
                int read = segmentIndexStreamRef.read(i5);
                if (read < 0) {
                    this.m_segmentParamIndex.add(read);
                } else {
                    byte read2 = segmentFlagsStreamRef.read(i5);
                    this.m_segmentParamIndex.add(this.m_curveParamwritePoint);
                    int segmentDataSize = getSegmentDataSize((byte) (read2 & 7));
                    this.m_segmentParams.addRange(segmentDataStreamRef, read, segmentDataSize, true, 1);
                    this.m_curveParamwritePoint += segmentDataSize;
                }
            }
        } else {
            AttributeStreamOfInt32 attributeStreamOfInt32 = this.m_segmentParamIndex;
            if (attributeStreamOfInt32 != null) {
                attributeStreamOfInt32.resize(this.m_pointCount, -1.0d);
                this.m_segmentFlags.resize(this.m_pointCount, 1.0d);
            }
        }
        this.m_pathFlags.add((byte) 0);
        byte read3 = (byte) (multiPathImpl.getPathFlagsStreamRef().read(pathFlagsStreamRef.size() - 2) & (-5));
        if (this.m_bPolygon) {
            read3 = (byte) (read3 | 1);
        }
        this.m_pathFlags.write(attributeStreamOfInt8.size() - 2, read3);
    }

    public void addPath(Point2D[] point2DArr, int i, boolean z) {
        if (i > point2DArr.length) {
            throw new IllegalArgumentException();
        }
        int i2 = 0;
        this.m_bPathStarted = false;
        int i3 = this.m_pointCount;
        _verifyAllStreams();
        int i4 = i3 + i;
        this.m_paths.add(i4);
        d(i4);
        _verifyAllStreams();
        AttributeStreamOfInt32 attributeStreamOfInt32 = this.m_segmentParamIndex;
        if (attributeStreamOfInt32 != null) {
            attributeStreamOfInt32.resize(this.m_pointCount, -1.0d);
            this.m_segmentFlags.resize(this.m_pointCount, 1.0d);
        }
        this.m_pathFlags.add((byte) 0);
        if (this.m_bPolygon) {
            AttributeStreamOfInt8 attributeStreamOfInt8 = this.m_pathFlags;
            attributeStreamOfInt8.write(attributeStreamOfInt8.size() - 2, (byte) 1);
        }
        AttributeStreamOfDbl attributeStreamOfDbl = (AttributeStreamOfDbl) this.b[0];
        while (i2 < i) {
            int i5 = z ? i2 : (i - i2) - 1;
            int i6 = i3 * 2;
            attributeStreamOfDbl.write(i6, point2DArr[i5].x);
            attributeStreamOfDbl.write(i6 + 1, point2DArr[i5].y);
            i2++;
            i3++;
        }
    }

    public void reverseAllPaths() {
        int pathCount = getPathCount();
        for (int i = 0; i < pathCount; i++) {
            reversePath(i);
        }
    }

    public void reversePath(int i) {
        _verifyAllStreams();
        if (i >= getPathCount()) {
            throw new IllegalArgumentException();
        }
        boolean _hasDirtyFlag = _hasDirtyFlag(512);
        boolean _hasDirtyFlag2 = _hasDirtyFlag(48);
        int pathStart = getPathStart(i);
        int pathSize = getPathSize(i);
        int attributeCount = this.m_description.getAttributeCount();
        for (int i2 = 0; i2 < attributeCount; i2++) {
            if (this.b[i2] != null) {
                int componentCount = VertexDescription.getComponentCount(this.m_description._getSemanticsImpl(i2));
                this.b[i2].reverseRange(componentCount * pathStart, componentCount * pathSize, componentCount);
            }
        }
        notifyModified(1013);
        if (!_hasDirtyFlag) {
            this.m_cachedRingAreas2D.write(i, -this.m_cachedRingAreas2D.read(i));
            _setDirtyFlag(512, false);
        }
        if (_hasDirtyFlag2) {
            return;
        }
        _setDirtyFlag(48, false);
    }

    public void removePath(int i) {
        _verifyAllStreams();
        int pathCount = getPathCount();
        int i2 = i < 0 ? pathCount - 1 : i;
        if (i2 >= pathCount) {
            throw new IllegalArgumentException();
        }
        int isSimple = getIsSimple(Utils.DOUBLE_EPSILON);
        if (isSimple == 2 && i2 != pathCount - 1 && isExteriorRing(i2) && isExteriorRing(i2 + 1)) {
            isSimple = 1;
        }
        boolean _hasDirtyFlag = _hasDirtyFlag(512);
        int pathStart = getPathStart(i2);
        int pathSize = getPathSize(i2);
        int attributeCount = this.m_description.getAttributeCount();
        for (int i3 = 0; i3 < attributeCount; i3++) {
            if (this.b[i3] != null) {
                int componentCount = VertexDescription.getComponentCount(this.m_description._getSemanticsImpl(i3));
                this.b[i3].eraseRange(componentCount * pathStart, componentCount * pathSize, componentCount * this.m_pointCount);
            }
        }
        int i4 = i2 + 1;
        for (int i5 = i4; i5 <= pathCount; i5++) {
            this.m_paths.write(i5 - 1, this.m_paths.read(i5) - pathSize);
        }
        if (this.m_pathFlags == null) {
            while (i4 <= pathCount) {
                this.m_pathFlags.write(i4 - 1, this.m_pathFlags.read(i4));
                i4++;
            }
        }
        this.m_paths.resize(pathCount);
        this.m_pathFlags.resize(pathCount);
        this.m_pointCount -= pathSize;
        this.m_reservedPointCount -= pathSize;
        notifyModified(1013);
        if (isSimple == 1) {
            a(1, this.m_simpleTolerance);
        } else if (isSimple == 2) {
            a(2, this.m_simpleTolerance);
        }
        if (_hasDirtyFlag) {
            return;
        }
        this.m_cachedRingAreas2D.eraseRange(i2, 1, pathCount);
        this.m_cachedRingAreas2D.resize(pathCount - 1);
        _setDirtyFlag(512, false);
    }

    public void insertPath(int i, MultiPathImpl multiPathImpl, int i2, boolean z) {
        int i3;
        int i4 = i;
        int i5 = i2;
        if (i5 >= multiPathImpl.getPathCount()) {
            throw new IllegalArgumentException();
        }
        int pathCount = getPathCount();
        if (i4 > pathCount) {
            throw new IllegalArgumentException();
        }
        if (i4 < 0) {
            i4 = pathCount;
        }
        if (i5 < 0) {
            i5 = multiPathImpl.getPathCount() - 1;
        }
        this.m_bPathStarted = false;
        mergeVertexDescription(multiPathImpl.m_description);
        multiPathImpl._verifyAllStreams();
        int pathStart = multiPathImpl.getPathStart(i5);
        int pathSize = multiPathImpl.getPathSize(i5);
        int i6 = this.m_pointCount;
        d(this.m_pointCount + pathSize);
        _verifyAllStreams();
        int pathStart2 = i4 < pathCount ? getPathStart(i4) : i6;
        int attributeCount = this.m_description.getAttributeCount();
        for (int i7 = 0; i7 < attributeCount; i7++) {
            int _getSemanticsImpl = this.m_description._getSemanticsImpl(i7);
            int attributeIndex = multiPathImpl.m_description.getAttributeIndex(_getSemanticsImpl);
            int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
            if (attributeIndex >= 0 && multiPathImpl.b[attributeIndex] != null) {
                this.b[i7].insertRange(pathStart2 * componentCount, multiPathImpl.b[attributeIndex], componentCount * pathStart, componentCount * pathSize, z, componentCount, componentCount * i6);
            } else {
                this.b[i7].insertRange(pathStart2 * componentCount, VertexDescription.getDefaultValue(_getSemanticsImpl), componentCount * pathSize, componentCount * i6);
            }
        }
        this.m_paths.add(i6 + pathSize);
        int i8 = pathCount;
        while (true) {
            i3 = i4 + 1;
            if (i8 < i3) {
                break;
            }
            this.m_paths.write(i8, this.m_paths.read(i8 - 1) + pathSize);
            i8--;
        }
        multiPathImpl.hasNonLinearSegments(i5);
        this.m_pathFlags.add((byte) 0);
        for (int i9 = pathCount - 1; i9 >= i3; i9--) {
            this.m_pathFlags.write(i9 + 1, (byte) (this.m_pathFlags.read(i9) & (-5)));
        }
        byte read = (byte) (multiPathImpl.getPathFlagsStreamRef().read(i5) & (-5));
        if (this.m_bPolygon) {
            read = (byte) (read | 1);
        }
        this.m_pathFlags.write(i4, read);
    }

    public void insertPath(int i, Point2D[] point2DArr, int i2, int i3, boolean z) {
        int i4;
        int i5;
        int i6 = i;
        int pathCount = getPathCount();
        if (i6 > pathCount) {
            throw new IllegalArgumentException();
        }
        if (i6 < 0) {
            i6 = pathCount;
        }
        this.m_bPathStarted = false;
        int i7 = this.m_pointCount;
        if (point2DArr != null) {
            d(this.m_pointCount + i3);
            _verifyAllStreams();
            int pathStart = i6 < pathCount ? getPathStart(i6) : i7;
            int attributeCount = this.m_description.getAttributeCount();
            int i8 = 0;
            while (i8 < attributeCount) {
                int _getSemanticsImpl = this.m_description._getSemanticsImpl(i8);
                if (_getSemanticsImpl == 0) {
                    this.b[i8].writeRange((pathStart + i3) * 2, (i7 - i6) * 2, this.b[i8], pathStart * 2, true, 2);
                    AttributeStreamOfDbl attributeStreamOfDbl = (AttributeStreamOfDbl) getAttributeStreamRef(_getSemanticsImpl);
                    int i9 = pathStart;
                    int i10 = 0;
                    while (i10 < i3) {
                        int i11 = z ? i2 + i10 : ((i2 + i3) - i10) - 1;
                        int i12 = i9 * 2;
                        attributeStreamOfDbl.write(i12, point2DArr[i11].x);
                        attributeStreamOfDbl.write(i12 + 1, point2DArr[i11].y);
                        i10++;
                        i9++;
                        i7 = i7;
                    }
                    i5 = i7;
                } else {
                    i5 = i7;
                    int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
                    this.b[i8].insertRange(pathStart * componentCount, VertexDescription.getDefaultValue(_getSemanticsImpl), componentCount * i3, componentCount * i5);
                }
                i8++;
                i7 = i5;
            }
        } else {
            _verifyAllStreams();
        }
        this.m_paths.add(this.m_pointCount);
        int i13 = pathCount;
        while (true) {
            i4 = i6 + 1;
            if (i13 < i4) {
                break;
            }
            this.m_paths.write(i13, this.m_paths.read(i13 - 1) + i3);
            i13--;
        }
        this.m_pathFlags.add((byte) 0);
        for (int i14 = pathCount - 1; i14 >= i4; i14--) {
            this.m_pathFlags.write(i14 + 1, (byte) (this.m_pathFlags.read(i14) & (-5)));
        }
        if (this.m_bPolygon) {
            this.m_pathFlags.write(i6, (byte) 1);
        }
    }

    public void insertPoints(int i, int i2, MultiPathImpl multiPathImpl, int i3, int i4, int i5, boolean z) {
        int i6 = i2;
        int i7 = i5;
        int pathCount = i < 0 ? getPathCount() : i;
        int pathCount2 = i3 < 0 ? multiPathImpl.getPathCount() - 1 : i3;
        if (pathCount > getPathCount() || i6 > getPathSize(pathCount) || pathCount2 >= multiPathImpl.getPathCount() || i7 > multiPathImpl.getPathSize(pathCount2)) {
            throw new GeometryException("index out of bounds");
        }
        if (i7 == 0) {
            return;
        }
        mergeVertexDescription(multiPathImpl.m_description);
        if (pathCount == getPathCount()) {
            this.m_paths.add(this.m_pointCount);
            byte read = (byte) (multiPathImpl.m_pathFlags.read(pathCount2) & (-5));
            if (!this.m_bPolygon) {
                this.m_pathFlags.add(read);
            } else {
                this.m_pathFlags.add((byte) (read | 1));
            }
        }
        if (i6 < 0) {
            i6 = getPathSize(pathCount);
        }
        int i8 = this.m_pointCount;
        d(this.m_pointCount + i7);
        _verifyAllStreams();
        multiPathImpl._verifyAllStreams();
        int pathStart = getPathStart(pathCount) + i6;
        if (i7 < 0) {
            i7 = multiPathImpl.getPathSize(pathCount2);
        }
        int pathStart2 = multiPathImpl.getPathStart(pathCount2);
        int i9 = pathStart2 + i7;
        int attributeCount = this.m_description.getAttributeCount();
        for (int i10 = 0; i10 < attributeCount; i10++) {
            int _getSemanticsImpl = this.m_description._getSemanticsImpl(i10);
            int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
            int attributeIndex = multiPathImpl.m_description.getAttributeIndex(_getSemanticsImpl);
            if (attributeIndex < 0 || multiPathImpl.b[attributeIndex] == null) {
                this.b[i10].insertRange(componentCount * pathStart, VertexDescription.getDefaultValue(_getSemanticsImpl), i9 * componentCount, componentCount * i8);
            } else {
                this.b[i10].insertRange(componentCount * pathStart, multiPathImpl.b[attributeIndex], componentCount * (pathStart2 + i4), i7 * componentCount, z, componentCount, componentCount * i8);
            }
        }
        if (hasNonLinearSegments()) {
            this.m_segmentFlags.writeRange(getPathStart(pathCount) + i6 + i7, (i8 - getPathStart(pathCount)) - i6, this.m_segmentFlags, getPathStart(pathCount) + i6, true, 1);
            this.m_segmentParamIndex.writeRange(getPathStart(pathCount) + i6 + i7, (i8 - getPathStart(pathCount)) - i6, this.m_segmentParamIndex, getPathStart(pathCount) + i6, true, 1);
            int pathStart3 = getPathStart(pathCount) + i6 + i7;
            for (int pathStart4 = getPathStart(pathCount) + i6; pathStart4 < pathStart3; pathStart4++) {
                this.m_segmentFlags.write(pathStart4, (byte) 1);
                this.m_segmentParamIndex.write(pathStart4, -1);
            }
        }
        if (multiPathImpl.hasNonLinearSegments(pathCount2)) {
            throw new GeometryException("internal error");
        }
        int pathCount3 = getPathCount();
        for (int i11 = pathCount + 1; i11 <= pathCount3; i11++) {
            this.m_paths.write(i11, this.m_paths.read(i11) + i7);
        }
    }

    public void insertPoints(int i, int i2, Point2D[] point2DArr, int i3, int i4, boolean z) {
        int i5 = i2;
        int pathCount = i < 0 ? getPathCount() : i;
        if (pathCount > getPathCount() || i5 > getPathSize(pathCount) || i3 < 0 || i4 > point2DArr.length) {
            throw new GeometryException("index out of bounds");
        }
        if (i4 == 0) {
            return;
        }
        if (pathCount == getPathCount()) {
            this.m_paths.add(this.m_pointCount);
            if (!this.m_bPolygon) {
                this.m_pathFlags.add((byte) 0);
            } else {
                this.m_pathFlags.add((byte) 1);
            }
        }
        if (i5 < 0) {
            i5 = getPathSize(pathCount);
        }
        int i6 = i5;
        _verifyAllStreams();
        int i7 = this.m_pointCount;
        d(this.m_pointCount + i4);
        _verifyAllStreams();
        int attributeCount = this.m_description.getAttributeCount();
        for (int i8 = 0; i8 < attributeCount; i8++) {
            int _getSemanticsImpl = this.m_description._getSemanticsImpl(i8);
            int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
            this.b[i8].writeRange(componentCount * (getPathStart(pathCount) + i6 + i4), ((i7 - getPathStart(pathCount)) - i6) * componentCount, this.b[i8], componentCount * (getPathStart(pathCount) + i6), true, componentCount);
            if (i8 == 0) {
                ((AttributeStreamOfDbl) this.b[i8]).writeRange(componentCount * (getPathStart(pathCount) + i6), i4, point2DArr, i3, z);
            } else {
                this.b[i8].setRange(VertexDescription.getDefaultValue(_getSemanticsImpl), (getPathStart(pathCount) + i6) * componentCount, componentCount * i4);
            }
        }
        if (hasNonLinearSegments()) {
            this.m_segmentFlags.writeRange(getPathStart(pathCount) + i6 + i4, (i7 - getPathStart(pathCount)) - i6, this.m_segmentFlags, getPathStart(pathCount) + i6, true, 1);
            this.m_segmentParamIndex.writeRange(getPathStart(pathCount) + i6 + i4, (i7 - getPathStart(pathCount)) - i6, this.m_segmentParamIndex, getPathStart(pathCount) + i6, true, 1);
            this.m_segmentFlags.setRange(1.0d, getPathStart(pathCount) + i6, i4);
            this.m_segmentParamIndex.setRange(-1.0d, getPathStart(pathCount) + i6, i4);
        }
        int pathCount2 = getPathCount();
        for (int i9 = pathCount + 1; i9 <= pathCount2; i9++) {
            AttributeStreamOfInt32 attributeStreamOfInt32 = this.m_paths;
            attributeStreamOfInt32.write(i9, attributeStreamOfInt32.read(i9) + i4);
        }
    }

    public void insertPoint(int i, int i2, Point2D point2D) {
        int pathCount = getPathCount();
        if (i < 0) {
            i = getPathCount();
        }
        if (i >= pathCount || i2 > getPathSize(i)) {
            throw new GeometryException("index out of bounds");
        }
        if (i == getPathCount()) {
            this.m_paths.add(this.m_pointCount);
            if (!this.m_bPolygon) {
                this.m_pathFlags.add((byte) 0);
            } else {
                this.m_pathFlags.add((byte) 1);
            }
        }
        if (i2 < 0) {
            i2 = getPathSize(i);
        }
        int i3 = this.m_pointCount;
        d(this.m_pointCount + 1);
        _verifyAllStreams();
        int pathStart = getPathStart(i) + i2;
        ((AttributeStreamOfDbl) this.b[0]).insert(pathStart * 2, point2D, i3 * 2);
        int attributeCount = this.m_description.getAttributeCount();
        for (int i4 = 1; i4 < attributeCount; i4++) {
            int _getSemanticsImpl = this.m_description._getSemanticsImpl(i4);
            int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
            this.b[i4].insertRange(componentCount * pathStart, VertexDescription.getDefaultValue(_getSemanticsImpl), componentCount, componentCount * i3);
        }
        for (int i5 = i + 1; i5 <= pathCount; i5++) {
            AttributeStreamOfInt32 attributeStreamOfInt32 = this.m_paths;
            attributeStreamOfInt32.write(i5, attributeStreamOfInt32.read(i5) + 1);
        }
    }

    public void insertPoint(int i, int i2, Point point) {
        int i3 = i2;
        int pathCount = getPathCount();
        int pathCount2 = i < 0 ? getPathCount() : i;
        if (pathCount2 >= pathCount || i3 > getPathSize(pathCount2)) {
            throw new GeometryException("index out of bounds");
        }
        if (pathCount2 == getPathCount()) {
            this.m_paths.add(this.m_pointCount);
            if (!this.m_bPolygon) {
                this.m_pathFlags.add((byte) 0);
            } else {
                this.m_pathFlags.add((byte) 1);
            }
        }
        if (i3 < 0) {
            i3 = getPathSize(pathCount2);
        }
        mergeVertexDescription(point.getDescription());
        int i4 = this.m_pointCount;
        d(this.m_pointCount + 1);
        _verifyAllStreams();
        int pathStart = getPathStart(pathCount2);
        int attributeCount = this.m_description.getAttributeCount();
        for (int i5 = 0; i5 < attributeCount; i5++) {
            int _getSemanticsImpl = this.m_description._getSemanticsImpl(i5);
            int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
            if (point.e(_getSemanticsImpl)) {
                this.b[i5].insertAttributes((pathStart + i3) * componentCount, point, _getSemanticsImpl, componentCount * i4);
            } else {
                this.b[i5].insertRange(componentCount * (pathStart + i3), VertexDescription.getDefaultValue(_getSemanticsImpl), componentCount, componentCount * i4);
            }
        }
        for (int i6 = pathCount2 + 1; i6 <= pathCount; i6++) {
            AttributeStreamOfInt32 attributeStreamOfInt32 = this.m_paths;
            attributeStreamOfInt32.write(i6, attributeStreamOfInt32.read(i6) + 1);
        }
        notifyModified(1013);
    }

    public void removePoint(int i, int i2) {
        int pathCount = getPathCount();
        if (i < 0) {
            i = pathCount - 1;
        }
        if (i >= pathCount || i2 >= getPathSize(i)) {
            throw new GeometryException("index out of bounds");
        }
        _verifyAllStreams();
        int pathStart = getPathStart(i);
        if (i2 < 0) {
            i2 = getPathSize(i) - 1;
        }
        int i3 = pathStart + i2;
        int attributeCount = this.m_description.getAttributeCount();
        for (int i4 = 0; i4 < attributeCount; i4++) {
            if (this.b[i4] != null) {
                int componentCount = VertexDescription.getComponentCount(this.m_description._getSemanticsImpl(i4));
                this.b[i4].eraseRange(componentCount * i3, componentCount, this.m_pointCount * componentCount);
            }
        }
        while (pathCount >= i + 1) {
            this.m_paths.write(pathCount, this.m_paths.read(pathCount) - 1);
            pathCount--;
        }
        this.m_pointCount--;
        this.m_reservedPointCount--;
        notifyModified(1013);
    }

    public void removePoint(int i) {
        int pathIndexFromPointIndex = getPathIndexFromPointIndex(i);
        removePoint(pathIndexFromPointIndex, i - getPathStart(pathIndexFromPointIndex));
    }

    @Override // com.esri.core.geometry.Geometry
    public void setEmpty() {
        this.m_curveParamwritePoint = 0;
        this.m_bPathStarted = false;
        this.m_paths = null;
        this.m_pathFlags = null;
        this.m_segmentParamIndex = null;
        this.m_segmentFlags = null;
        this.m_segmentParams = null;
        l();
    }

    @Override // com.esri.core.geometry.Geometry
    public void applyTransformation(Transformation2D transformation2D) {
        applyTransformation(transformation2D, -1);
    }

    public void applyTransformation(Transformation2D transformation2D, int i) {
        int pathEnd;
        boolean z;
        int read;
        if (isEmpty() || transformation2D.isIdentity()) {
            return;
        }
        _verifyAllStreams();
        int i2 = 0;
        AttributeStreamOfDbl attributeStreamOfDbl = (AttributeStreamOfDbl) this.b[0];
        Point2D point2D = new Point2D();
        Point2D point2D2 = new Point2D();
        if (i < 0) {
            hasNonLinearSegments();
        } else {
            hasNonLinearSegments(i);
        }
        if (i < 0) {
            z = hasNonLinearSegments();
            pathEnd = this.m_pointCount;
        } else {
            boolean hasNonLinearSegments = hasNonLinearSegments(i);
            int pathStart = getPathStart(i);
            pathEnd = getPathEnd(i);
            z = hasNonLinearSegments;
            i2 = pathStart;
        }
        while (i2 < pathEnd) {
            int i3 = i2 * 2;
            point2D.x = attributeStreamOfDbl.read(i3);
            int i4 = i3 + 1;
            point2D.y = attributeStreamOfDbl.read(i4);
            if (z && (read = this.m_segmentParamIndex.read(i2)) >= 0) {
                int read2 = this.m_segmentFlags.read(i2) & 7;
                if (read2 == 2) {
                    point2D2.x = this.m_segmentParams.read(read);
                    int i5 = read + 1;
                    point2D2.y = this.m_segmentParams.read(i5);
                    transformation2D.a(point2D2, point2D2);
                    this.m_segmentParams.write(read, point2D2.x);
                    this.m_segmentParams.write(i5, point2D2.y);
                    int i6 = read + 3;
                    point2D2.x = this.m_segmentParams.read(i6);
                    int i7 = read + 4;
                    point2D2.y = this.m_segmentParams.read(i7);
                    transformation2D.a(point2D2, point2D2);
                    this.m_segmentParams.write(i6, point2D2.x);
                    this.m_segmentParams.write(i7, point2D2.y);
                } else if (read2 == 4) {
                    throw new GeometryException("internal error");
                }
            }
            transformation2D.a(point2D, point2D);
            attributeStreamOfDbl.write(i3, point2D.x);
            attributeStreamOfDbl.write(i4, point2D.y);
            i2++;
        }
        notifyModified(1013);
    }

    @Override // com.esri.core.geometry.Geometry
    public void applyTransformation(Transformation3D transformation3D) {
        int read;
        if (isEmpty()) {
            return;
        }
        addAttribute(1);
        _verifyAllStreams();
        AttributeStreamOfDbl attributeStreamOfDbl = (AttributeStreamOfDbl) this.b[0];
        AttributeStreamOfDbl attributeStreamOfDbl2 = (AttributeStreamOfDbl) this.b[1];
        Point3D point3D = new Point3D();
        Point3D point3D2 = new Point3D();
        boolean hasNonLinearSegments = hasNonLinearSegments();
        for (int i = 0; i < this.m_pointCount; i++) {
            int i2 = i * 2;
            point3D.x = attributeStreamOfDbl.read(i2);
            int i3 = i2 + 1;
            point3D.y = attributeStreamOfDbl.read(i3);
            point3D.z = attributeStreamOfDbl2.read(i);
            if (hasNonLinearSegments && (read = this.m_segmentParamIndex.read(i)) >= 0) {
                int read2 = this.m_segmentFlags.read(i) & 7;
                if (read2 == 2) {
                    point3D2.x = this.m_segmentParams.read(read);
                    int i4 = read + 1;
                    point3D2.y = this.m_segmentParams.read(i4);
                    point3D2.z = this.m_segmentParams.read(read + 2);
                    Point3D transform = transformation3D.transform(point3D2);
                    this.m_segmentParams.write(read, transform.x);
                    this.m_segmentParams.write(i4, transform.y);
                    this.m_segmentParams.write(i4, transform.z);
                    int i5 = read + 3;
                    transform.x = this.m_segmentParams.read(i5);
                    int i6 = read + 4;
                    transform.y = this.m_segmentParams.read(i6);
                    int i7 = read + 5;
                    transform.z = this.m_segmentParams.read(i7);
                    point3D2 = transformation3D.transform(transform);
                    this.m_segmentParams.write(i5, point3D2.x);
                    this.m_segmentParams.write(i6, point3D2.y);
                    this.m_segmentParams.write(i7, point3D2.z);
                } else if (read2 == 4) {
                    throw new GeometryException("internal error");
                }
            }
            point3D = transformation3D.transform(point3D);
            attributeStreamOfDbl.write(i2, point3D.x);
            attributeStreamOfDbl.write(i3, point3D.y);
            attributeStreamOfDbl2.write(i, point3D.z);
        }
        notifyModified(1013);
    }

    @Override // com.esri.core.geometry.MultiVertexGeometryImpl
    protected void _verifyStreamsImpl() {
        if (this.m_paths == null) {
            this.m_paths = (AttributeStreamOfInt32) AttributeStreamBase.createIndexStream(1, 0);
            this.m_pathFlags = (AttributeStreamOfInt8) AttributeStreamBase.createByteStream(1, (byte) 0);
        }
        AttributeStreamOfInt8 attributeStreamOfInt8 = this.m_segmentFlags;
        if (attributeStreamOfInt8 != null) {
            attributeStreamOfInt8.resize(this.m_reservedPointCount, 1.0d);
            this.m_segmentParamIndex.resize(this.m_reservedPointCount, -1.0d);
        }
    }

    @Override // com.esri.core.geometry.MultiVertexGeometryImpl
    void a(MultiVertexGeometryImpl multiVertexGeometryImpl) {
        MultiPathImpl multiPathImpl = (MultiPathImpl) multiVertexGeometryImpl;
        multiPathImpl.m_bPathStarted = false;
        multiPathImpl.m_curveParamwritePoint = this.m_curveParamwritePoint;
        AttributeStreamOfInt32 attributeStreamOfInt32 = this.m_paths;
        if (attributeStreamOfInt32 != null) {
            multiPathImpl.m_paths = new AttributeStreamOfInt32(attributeStreamOfInt32);
        } else {
            multiPathImpl.m_paths = null;
        }
        AttributeStreamOfInt8 attributeStreamOfInt8 = this.m_pathFlags;
        if (attributeStreamOfInt8 != null) {
            multiPathImpl.m_pathFlags = new AttributeStreamOfInt8(attributeStreamOfInt8);
        } else {
            multiPathImpl.m_pathFlags = null;
        }
        AttributeStreamOfInt32 attributeStreamOfInt322 = this.m_segmentParamIndex;
        if (attributeStreamOfInt322 != null) {
            multiPathImpl.m_segmentParamIndex = new AttributeStreamOfInt32(attributeStreamOfInt322);
        } else {
            multiPathImpl.m_segmentParamIndex = null;
        }
        AttributeStreamOfInt8 attributeStreamOfInt82 = this.m_segmentFlags;
        if (attributeStreamOfInt82 != null) {
            multiPathImpl.m_segmentFlags = new AttributeStreamOfInt8(attributeStreamOfInt82);
        } else {
            multiPathImpl.m_segmentFlags = null;
        }
        AttributeStreamOfDbl attributeStreamOfDbl = this.m_segmentParams;
        if (attributeStreamOfDbl != null) {
            multiPathImpl.m_segmentParams = new AttributeStreamOfDbl(attributeStreamOfDbl);
        } else {
            multiPathImpl.m_segmentParams = null;
        }
        multiPathImpl.m_cachedLength2D = this.m_cachedLength2D;
        multiPathImpl.m_cachedArea2D = this.m_cachedArea2D;
        if (!_hasDirtyFlag(512)) {
            multiPathImpl.m_cachedRingAreas2D = this.m_cachedRingAreas2D;
        } else {
            multiPathImpl.m_cachedRingAreas2D = null;
        }
    }

    @Override // com.esri.core.geometry.Geometry
    public double calculateLength2D() {
        if (!_hasDirtyFlag(128)) {
            return this.m_cachedLength2D;
        }
        SegmentIteratorImpl querySegmentIterator = querySegmentIterator();
        double d = Utils.DOUBLE_EPSILON;
        while (querySegmentIterator.nextPath()) {
            while (querySegmentIterator.hasNextSegment()) {
                d += querySegmentIterator.nextSegment().calculateLength2D();
            }
        }
        this.m_cachedLength2D = d;
        _setDirtyFlag(128, false);
        return d;
    }

    @Override // com.esri.core.geometry.MultiVertexGeometryImpl
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if ((obj instanceof MultiPathImpl) && super.equals(obj)) {
            MultiPathImpl multiPathImpl = (MultiPathImpl) obj;
            int pathCount = getPathCount();
            if (pathCount != multiPathImpl.getPathCount()) {
                return false;
            }
            AttributeStreamOfInt32 attributeStreamOfInt32 = this.m_paths;
            if (attributeStreamOfInt32 == null || attributeStreamOfInt32.equals(multiPathImpl.m_paths, 0, pathCount + 1)) {
                AttributeStreamOfInt8 attributeStreamOfInt8 = this.m_pathFlags;
                if (attributeStreamOfInt8 == null || attributeStreamOfInt8.equals(multiPathImpl.m_pathFlags, 0, pathCount)) {
                    return super.equals(obj);
                }
                return false;
            }
            return false;
        }
        return false;
    }

    public SegmentIteratorImpl querySegmentIteratorAtVertex(int i) {
        if (i < 0 || i >= getPointCount()) {
            throw new IndexOutOfBoundsException();
        }
        return new SegmentIteratorImpl(this, i);
    }

    public SegmentIteratorImpl querySegmentIterator() {
        return new SegmentIteratorImpl(this);
    }

    @Override // com.esri.core.geometry.MultiVertexGeometryImpl
    public void _updateXYImpl(boolean z) {
        Segment nextCurve;
        super._updateXYImpl(z);
        if (hasNonLinearSegments()) {
            SegmentIteratorImpl querySegmentIterator = querySegmentIterator();
            while (querySegmentIterator.nextPath()) {
                while (querySegmentIterator.hasNextSegment() && (nextCurve = querySegmentIterator.nextCurve()) != null) {
                    Envelope2D envelope2D = new Envelope2D();
                    nextCurve.queryEnvelope2D(envelope2D);
                    this.d.b(envelope2D);
                }
            }
        }
    }

    @Override // com.esri.core.geometry.MultiVertexGeometryImpl
    public void _notifyModifiedAllImpl() {
        AttributeStreamOfInt32 attributeStreamOfInt32 = this.m_paths;
        if (attributeStreamOfInt32 == null || attributeStreamOfInt32.size() == 0) {
            this.m_pointCount = 0;
            return;
        }
        AttributeStreamOfInt32 attributeStreamOfInt322 = this.m_paths;
        this.m_pointCount = attributeStreamOfInt322.read(attributeStreamOfInt322.size() - 1);
    }

    @Override // com.esri.core.geometry.Geometry
    public double calculateArea2D() {
        if (this.m_bPolygon) {
            _updateArea2D();
            return this.m_cachedArea2D;
        }
        return Utils.DOUBLE_EPSILON;
    }

    public boolean isExteriorRing(int i) {
        if (this.m_bPolygon) {
            if (!_hasDirtyFlag(4)) {
                return (this.m_pathFlags.read(i) & 4) != 0;
            }
            _updateRingAreas2D();
            return this.m_cachedRingAreas2D.read(i) > Utils.DOUBLE_EPSILON;
        }
        return false;
    }

    public double calculateRingArea2D(int i) {
        if (this.m_bPolygon) {
            _updateRingAreas2D();
            return this.m_cachedRingAreas2D.read(i);
        }
        return Utils.DOUBLE_EPSILON;
    }

    public void _updateArea2D() {
        if (_hasDirtyFlag(512)) {
            _updateRingAreas2D();
        } else if (_hasDirtyFlag(256)) {
            this.m_cachedArea2D = Utils.DOUBLE_EPSILON;
            int pathCount = getPathCount();
            for (int i = 0; i < pathCount; i++) {
                this.m_cachedArea2D += this.m_cachedRingAreas2D.read(i);
            }
            _setDirtyFlag(256, false);
        }
    }

    public void _updateRingAreas2D() {
        if (_hasDirtyFlag(512)) {
            int pathCount = getPathCount();
            AttributeStreamOfDbl attributeStreamOfDbl = this.m_cachedRingAreas2D;
            if (attributeStreamOfDbl == null) {
                this.m_cachedRingAreas2D = new AttributeStreamOfDbl(pathCount);
            } else if (attributeStreamOfDbl.size() != pathCount) {
                this.m_cachedRingAreas2D.resize(pathCount);
            }
            Point2D point2D = new Point2D();
            this.m_cachedArea2D = Utils.DOUBLE_EPSILON;
            SegmentIteratorImpl querySegmentIterator = querySegmentIterator();
            int i = 0;
            while (querySegmentIterator.nextPath()) {
                getXY(getPathStart(querySegmentIterator.getPathIndex()), point2D);
                double d = 0.0d;
                while (querySegmentIterator.hasNextSegment()) {
                    d += querySegmentIterator.nextSegment().a(point2D.x, point2D.y);
                }
                this.m_cachedArea2D += d;
                this.m_cachedRingAreas2D.write(i, d);
                i++;
            }
            _setDirtyFlag(512, false);
            _setDirtyFlag(256, false);
        }
    }

    public int a() {
        if (this.m_bPolygon) {
            _updateOGCFlags();
            int pathCount = getPathCount();
            int i = 0;
            for (int i2 = 0; i2 < pathCount; i2++) {
                if ((this.m_pathFlags.read(i2) & 4) != 0) {
                    i++;
                }
            }
            return i;
        }
        return 0;
    }

    protected void _updateOGCFlags() {
        if (_hasDirtyFlag(4)) {
            _updateRingAreas2D();
            int pathCount = getPathCount();
            AttributeStreamOfInt8 attributeStreamOfInt8 = this.m_pathFlags;
            if (attributeStreamOfInt8 == null || attributeStreamOfInt8.size() < pathCount) {
                this.m_pathFlags = (AttributeStreamOfInt8) AttributeStreamBase.createByteStream(pathCount + 1);
            }
            for (int i = 0; i < pathCount; i++) {
                if (this.m_cachedRingAreas2D.read(i) > Utils.DOUBLE_EPSILON) {
                    this.m_pathFlags.setBits(i, (byte) 4);
                } else {
                    this.m_pathFlags.a(i, (byte) 4);
                }
            }
            _setDirtyFlag(4, false);
        }
    }

    public int getPathIndexFromPointIndex(int i) {
        int i2;
        int i3 = this.e;
        int pathCount = getPathCount();
        if (i3 >= 0 && i3 < pathCount) {
            if (i >= getPathEnd(i3)) {
                i2 = i3 + 1;
            } else if (i >= getPathStart(i3)) {
                return i3;
            } else {
                i2 = i3 - 1;
            }
            if (i2 >= 0 && i2 < pathCount && i >= getPathStart(i2) && i < getPathEnd(i2)) {
                this.e = i2;
                return i2;
            }
        }
        int i4 = 0;
        if (pathCount < 5) {
            while (i4 < pathCount) {
                if (i < getPathEnd(i4)) {
                    this.e = i4;
                    return i4;
                }
                i4++;
            }
            throw new GeometryException("corrupted geometry");
        }
        int i5 = pathCount - 1;
        while (i5 > i4) {
            int i6 = ((i5 - i4) >> 1) + i4;
            if (i < getPathStart(i6)) {
                i5 = i6 - 1;
            } else if (i < getPathEnd(i6)) {
                this.e = i6;
                return i6;
            } else {
                i4 = i6 + 1;
            }
        }
        this.e = i4;
        return i4;
    }

    public int getSegmentCount() {
        int pointCount = getPointCount();
        if (!this.m_bPolygon) {
            pointCount -= getPathCount();
            int pathCount = getPathCount();
            for (int i = 0; i < pathCount; i++) {
                if (isClosedPath(i)) {
                    pointCount++;
                }
            }
        }
        return pointCount;
    }

    @Override // com.esri.core.geometry.Geometry
    public Geometry createInstance() {
        return new MultiPathImpl(this.m_bPolygon, getDescription());
    }

    @Override // com.esri.core.geometry.Geometry
    public int getDimension() {
        return this.m_bPolygon ? 2 : 1;
    }

    @Override // com.esri.core.geometry.Geometry
    public Geometry.Type getType() {
        return this.m_bPolygon ? Geometry.Type.POLYGON : Geometry.Type.POLYLINE;
    }

    public boolean isEnvelope() {
        return !_hasDirtyFlag(64);
    }

    public AttributeStreamOfInt32 getPathStreamRef() {
        throwIfEmpty();
        return this.m_paths;
    }

    public void setPathStreamRef(AttributeStreamOfInt32 attributeStreamOfInt32) {
        this.m_paths = attributeStreamOfInt32;
        notifyModified(16777215);
    }

    public AttributeStreamOfInt8 getSegmentFlagsStreamRef() {
        throwIfEmpty();
        return this.m_segmentFlags;
    }

    public AttributeStreamOfInt8 getPathFlagsStreamRef() {
        throwIfEmpty();
        return this.m_pathFlags;
    }

    public void setPathFlagsStreamRef(AttributeStreamOfInt8 attributeStreamOfInt8) {
        this.m_pathFlags = attributeStreamOfInt8;
        notifyModified(16777215);
    }

    public AttributeStreamOfInt32 getSegmentIndexStreamRef() {
        throwIfEmpty();
        return this.m_segmentParamIndex;
    }

    public AttributeStreamOfDbl getSegmentDataStreamRef() {
        throwIfEmpty();
        return this.m_segmentParams;
    }

    public int getPathCount() {
        AttributeStreamOfInt32 attributeStreamOfInt32 = this.m_paths;
        if (attributeStreamOfInt32 != null) {
            return attributeStreamOfInt32.size() - 1;
        }
        return 0;
    }

    public int getPathEnd(int i) {
        return this.m_paths.read(i + 1);
    }

    public int getPathSize(int i) {
        return this.m_paths.read(i + 1) - this.m_paths.read(i);
    }

    public int getPathStart(int i) {
        return this.m_paths.read(i);
    }

    public void setDirtyOGCFlags(boolean z) {
        _setDirtyFlag(4, z);
    }

    public boolean hasDirtyOGCStartFlags() {
        return _hasDirtyFlag(4);
    }

    public void setDirtyRingAreas2D(boolean z) {
        _setDirtyFlag(512, z);
    }

    public boolean hasDirtyRingAreas2D() {
        return _hasDirtyFlag(512);
    }

    public void setRingAreasStreamRef(AttributeStreamOfDbl attributeStreamOfDbl) {
        this.m_cachedRingAreas2D = attributeStreamOfDbl;
        _setDirtyFlag(512, false);
    }

    @Override // com.esri.core.geometry.MultiVertexGeometryImpl
    public boolean _buildRasterizedGeometryAccelerator(double d, Geometry.GeometryAccelerationDegree geometryAccelerationDegree) {
        if (this.c == null) {
            this.c = new GeometryAccelerators();
        }
        int rasterSizeFromAccelerationDegree = RasterizedGeometry2D.rasterSizeFromAccelerationDegree(geometryAccelerationDegree);
        RasterizedGeometry2D rasterizedGeometry = this.c.getRasterizedGeometry();
        if (rasterizedGeometry != null) {
            if (rasterizedGeometry.a() >= d && rasterSizeFromAccelerationDegree <= rasterizedGeometry.b()) {
                return true;
            }
            this.c.a(null);
        }
        this.c.a(RasterizedGeometry2D.create((MultiVertexGeometryImpl) this, d, rasterSizeFromAccelerationDegree));
        return true;
    }

    static void a(QuadTree quadTree, MultiPathImpl multiPathImpl, double d) {
        double d2 = d * 1.01d;
        quadTree.a = new Envelope2D();
        multiPathImpl.queryEnvelope2D(quadTree.a);
        quadTree.a.inflate(d2, d2);
        quadTree.d = new AttributeStreamOfInt32(0);
        quadTree.d.resize(7, -1.0d);
        quadTree.f = new AttributeStreamOfInt32(0);
        quadTree.e = new AttributeStreamOfDbl(0);
        Envelope2D envelope2D = new Envelope2D();
        SegmentIteratorImpl querySegmentIterator = multiPathImpl.querySegmentIterator();
        while (querySegmentIterator.nextPath()) {
            while (querySegmentIterator.hasNextSegment()) {
                Segment nextSegment = querySegmentIterator.nextSegment();
                int startPointIndex = querySegmentIterator.getStartPointIndex();
                nextSegment.queryEnvelope2D(envelope2D);
                envelope2D.inflate(d2, d2);
                quadTree.a(startPointIndex, envelope2D, (byte) 0, quadTree.a, 0, -1);
            }
        }
        quadTree.b = null;
    }

    @Override // com.esri.core.geometry.MultiVertexGeometryImpl
    public int hashCode() {
        int hashCode = super.hashCode();
        if (!b()) {
            int pathCount = getPathCount();
            AttributeStreamOfInt32 attributeStreamOfInt32 = this.m_paths;
            if (attributeStreamOfInt32 != null) {
                attributeStreamOfInt32.calculateHashImpl(hashCode, 0, pathCount + 1);
            }
            AttributeStreamOfInt8 attributeStreamOfInt8 = this.m_pathFlags;
            if (attributeStreamOfInt8 != null) {
                attributeStreamOfInt8.calculateHashImpl(hashCode, 0, pathCount);
            }
        }
        return hashCode;
    }

    public byte getSegmentFlags(int i) {
        AttributeStreamOfInt8 attributeStreamOfInt8 = this.m_segmentFlags;
        if (attributeStreamOfInt8 != null) {
            return attributeStreamOfInt8.read(i);
        }
        return (byte) 1;
    }

    public void getSegment(int i, SegmentBuffer segmentBuffer, boolean z) {
        int pathIndexFromPointIndex = getPathIndexFromPointIndex(i);
        if (i == getPathEnd(pathIndexFromPointIndex) - 1 && !isClosedPath(pathIndexFromPointIndex)) {
            throw new GeometryException("index out of bounds");
        }
        _verifyAllStreams();
        AttributeStreamOfInt8 segmentFlagsStreamRef = getSegmentFlagsStreamRef();
        int read = segmentFlagsStreamRef != null ? segmentFlagsStreamRef.read(i) & 7 : 1;
        if (read != 1) {
            if (read == 2) {
                throw new GeometryException("internal error");
            }
            if (read == 4) {
                throw new GeometryException("internal error");
            }
            throw new GeometryException("internal error");
        }
        segmentBuffer.createLine();
        Segment segment = segmentBuffer.get();
        if (!z) {
            segment.a(this.m_description);
        } else {
            segment.a(VertexDescriptionDesignerImpl.d());
        }
        int pathStart = (i == getPathEnd(pathIndexFromPointIndex) - 1 && isClosedPath(pathIndexFromPointIndex)) ? getPathStart(pathIndexFromPointIndex) : i + 1;
        Point2D point2D = new Point2D();
        getXY(i, point2D);
        segment.c(point2D);
        getXY(pathStart, point2D);
        segment.e(point2D);
        if (z) {
            return;
        }
        int attributeCount = this.m_description.getAttributeCount();
        for (int i2 = 1; i2 < attributeCount; i2++) {
            int _getSemanticsImpl = this.m_description._getSemanticsImpl(i2);
            int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
            for (int i3 = 0; i3 < componentCount; i3++) {
                segment.a(_getSemanticsImpl, i3, getAttributeAsDbl(_getSemanticsImpl, i, i3));
                segment.b(_getSemanticsImpl, i3, getAttributeAsDbl(_getSemanticsImpl, pathStart, i3));
            }
        }
    }
}
